package com.zyc.webtest.dao;

import com.zyc.webtest.domain.SysMenuEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * Created by lenovo on 2017/4/25.
 */
@Repository
//public interface SysMenuRepository extends Repository<SysMenuEntity, Integer> {
public interface SysMenuRepository extends JpaRepository<SysMenuEntity, Integer> {

    Optional<SysMenuEntity> findByMenuId(Integer menu_id);

//    @Query("SELECT m FROM SysRoleEntity r LEFT JOIN sys_role_menu rm ON r.role_id=rm.role_id INNER JOIN SysMenuEntity m ON rm.menu_id=m.menu_id where r.role_id=:role_id  ")
    @Query(value="select m.menu_id,m.parent_id,m.name,m.url,m.perms,m.menu_type,m.icon,m.order_num from sys_role r LEFT JOIN sys_role_menu rm ON r.role_id=rm.role_id INNER JOIN sys_menu m ON rm.menu_id=m.menu_id where r.role_name=:role_name  ",nativeQuery=true )
    Optional<List<SysMenuEntity>> findRoleMenu(@Param("role_name") String role_name);

}
